Edit or run this notebook

PlutoCon 2021 WYSIWYR Demo (MNIST)

6.7 Î¼s

Author: Connor Burns

102 s

In this notebook we will load a pretrained model for classifying MNIST handwritten digits from 28x28 greyscale images. However, this notebook is less about the model and more about interacting with it via "what you see is what you REST" features.

4.5 Î¼s
5.4 Î¼s

Loading Data

To start off we will download the MNIST dataset using the MLDatasets package.

6.5 Î¼s
8.2 s

Now we load a pre-trained model which has been serialized with Julia's native serialization library. The model is made up of 3 convolutional layers, 3 max pooling layers, and one dense layer.

6.8 Î¼s
serialized_model_path

Failed to connect to cot.llc port 80: Connection timed out while requesting http://cot.llc/mnist_conv

  1. (::Downloads.var"#9#18"{IOStream, Base.DevNull, Nothing, Vector{Pair{String, String}}, Float64, Nothing, Bool, Bool, String, Int64, Bool, Bool})(::Downloads.Curl.Easy)@Downloads.jl:356
  2. with_handle(::Downloads.var"#9#18"{IOStream, Base.DevNull, Nothing, Vector{Pair{String, String}}, Float64, Nothing, Bool, Bool, String, Int64, Bool, Bool}, ::Downloads.Curl.Easy)@Curl.jl:60
  3. #8@Downloads.jl:298[inlined]
  4. arg_write(::Downloads.var"#8#17"{Base.DevNull, Nothing, Vector{Pair{String, String}}, Float64, Nothing, Bool, Bool, String, Int64, Bool, Bool}, ::IOStream)@ArgTools.jl:112
  5. #7@Downloads.jl:297[inlined]
  6. arg_read@ArgTools.jl:61[inlined]
  7. var"#request#5"(::Nothing, ::IOStream, ::Nothing, ::Vector{Pair{String, String}}, ::Float64, ::Nothing, ::Bool, ::Bool, ::Nothing, ::typeof(Downloads.request), ::String)@Downloads.jl:296
  8. (::Downloads.var"#3#4"{Nothing, Vector{Pair{String, String}}, Float64, Nothing, Bool, Nothing, String})(::IOStream)@Downloads.jl:209
  9. arg_write(::Downloads.var"#3#4"{Nothing, Vector{Pair{String, String}}, Float64, Nothing, Bool, Nothing, String}, ::Nothing)@ArgTools.jl:101
  10. #download#2@Downloads.jl:208[inlined]
  11. download(::String, ::Nothing)@Downloads.jl:208
  12. #invokelatest#2@essentials.jl:708[inlined]
  13. invokelatest@essentials.jl:706[inlined]
  14. do_download@download.jl:33[inlined]
  15. download@download.jl:29[inlined]
  16. top-level scope@Local: 1[inlined]
---
model

UndefVarError: serialized_model_path not defined

  1. top-level scope@Local: 1
---

To test our model we will only load in the test data. Our model was trained with training data from MNIST.traindata() in another notebook.

3.7 Î¼s
1.3 s

test_x shape: (28, 28, 10000), test_y shape: (10000,)

9.4 ms

Testing the model (and building the API too!)

2.0 Î¼s

First we assign a variable input_images to a small slice of test data.

3.8 Î¼s

Start Index:

End Index:

27.9 ms
safe_start_index
1
200 ns
safe_end_index
10
400 ns
input_images_slice
1:10
100 ns
221 ms

For example, the first (and only) element in the sample is a 7

4.0 Î¼s
6.8 ms

Passing our input_images through the model loaded earlier, we get a 10x1 matrix, where each column corresponds to an input image, and each row corresponds to the class which the model thinks the image corresponds to. For example, a high value in the first row corresponds to a high confidence that the image contains a 0 digit.

The highest value by far is in the 8th index, which corresponds to the model predicting a 7 digit.

4.9 Î¼s
predictions

UndefVarError: model not defined

  1. top-level scope@Local: 1
---

The last step is to convert these predictions into numbers, then compare them to their true labels

3.4 Î¼s
output_labels

UndefVarError: predictions not defined

  1. top-level scope@Local: 1
---
test_labels
1.8 Î¼s

Finally we can measure the accuracy of the model by comparing our predictions to the actual labels and finding the average.

2.9 Î¼s

UndefVarError: output_labels not defined

  1. top-level scope@Local: 1
---
accuracy

UndefVarError: output_labels not defined

  1. top-level scope@Local: 1
---

Helpers

1.5 Î¼s
default (generic function with 1 method)
38.7 Î¼s
display_digit (generic function with 1 method)
26.8 Î¼s
Loading...i